<?php

include_once 'Classes/PHPCodeProvider.php';

$options = new CodeGeneratorOptions();
$writer = new IndentedTextWriter();
$provider = new PHPCodeProvider();

/*
 * Invoke a method named 'generateWinningCombination' of the current object
 */

$method1 = new MethodReferenceExpression(
    'generateWinningCombination', new ThisReferenceExpression());
$invoke1 = new MethodInvokeExpression($method1);

$provider->generateCodeFromExpression($invoke1, $writer, $options);

echo '<pre>' . 
    str_replace('<br />', '', highlight_string($writer->get_String(), true)) 
        . '<pre/>';

$writer->clear();

/*
 * Invoke a method named 'get_innerArray' of an object referenced by        
 * a variable named $combination
 */

$method2 = new MethodReferenceExpression(
    'get_innerArray', new VariableReferenceExpression('combination'));
$invoke2 = new MethodInvokeExpression($method2);

$provider->generateCodeFromExpression($invoke2, $writer, $options);

echo '<pre>' . 
    str_replace('<br />', '', highlight_string($writer->get_String(), true)) 
        . '<pre/>';

$writer->clear();

/*
 * Invoke a method named 'myMethod' of an object referenced by
 * a variable named $myObject, passing it four arguments:
 * $arg1, $arg2, 3.14 and false
 */

$method3 = new MethodReferenceExpression(
    'myMethod', new VariableReferenceExpression('myObject'));
$invoke3 = new MethodInvokeExpression($method3);
$invoke3->Parameters->add(new VariableReferenceExpression('arg1'));
$invoke3->Parameters->add(new VariableReferenceExpression('arg2'));
$invoke3->Parameters->add(new PrimitiveExpression(3.14));
$invoke3->Parameters->add(new PrimitiveExpression(false));

$provider->generateCodeFromExpression($invoke3, $writer, $options);

echo '<pre>' . 
    str_replace('<br />', '', highlight_string($writer->get_String(), true)) 
        . '<pre/>';



/*
 * The output should be:
 * 
 * $this->generateWinningCombination()
 *
 * $combination->get_innerArray()
 *
 * $myObject->myMethod($arg1, $arg2, 3.14, false)
 *
 * 
 */


?>
